<blockquote class="layui-elem-quote">
  <div class="layui-inline">
    <i class="layui-icon layui-icon-list layui-head-icon"></i>
    <span class="layui-font-16 layui-font-green">场次商品管理</span>
  </div>
  <div class="layui-pull-right">
    <a class="layui-btn layui-btn-primary layui-border-green" id="save">添加场次商品</a>
  </div>
</blockquote>
<div class="layui-card">
  <div class="layui-card-body">
    <form class="layui-form">
      <table class="layui-table">
        <thead>
          <tr>
          <th>ID</th>
          <th>图片</th>
          <th>商品名称</th>
          <th>销售价</th>
          <th>秒杀价</th>
          <th>秒杀库存</th>
          <th>创建时间</th>
          <th>操作</th>
          </tr> 
        </thead>
      <tbody>
        {foreach $list as $vo}
        <tr>
          <td>{$vo.id}</td>
          <td><img src="{$vo.main_image}"  class="layui-view-img"></td>
          <td class="goods-name">{$vo.goods_name}</td>
          <td>{$vo.sell_price}</td>
          <td>{$vo.spike_price}</td>
          <td>{$vo.spike_stock}</td>
          <td>{$vo.create_time}</td>
          <td>
            <a class="layui-btn layui-btn-sm layui-btn-danger goods-del" data-id="{$vo.id}">删除</a>
          </td>
        </tr>
        {/foreach}
      </tbody>
      </table>
      {$list|raw}
  </form>  
  </div>
</div>
<script>

    $('.goods-del').click(function(){
        let id = $(this).attr('data-id');
        $.get("{:url('/store/spike/session/goods/delete')}",{id:id},function(res){
              if(res.code==1){
                $.pjax({container: '#main',fragment: '#main'}).reload;
                layer.msg(res.msg,{icon:1});
                return false;
              }
              layer.msg(res.msg,{icon:2});
        });
    });

    $('#save').click(function(){
        let id = "{$spike_session_id}";
        layer.open({
            content: "{:url('/store/spike/goods/option',['ids'=>$ids])}",
            title:['选择秒杀商品'],
            btn:['确定','取消'],
            maxmin:true,
            type:2,
            area:["1000px","800px"],
            yes: function(index, layero){
                let checkbox =  $(layero).find('iframe').contents().find('input[type="checkbox"]:checked');
                
                if(checkbox.length<1){
                    layer.msg('请选择商品!',{icon:2});
                    return false;
                }

                param = [];

                checkbox.each(function(){
                    param.push({
                        spike_session_id:id,
                        spike_goods_id: $(this).val()
                    });
                });

                $.post("{:url('/store/spike/session/goods/save')}",{session_goods:param},function(res){
                    if(res.code ==1){
                        parent.layer.close(index);
                        parent.$.pjax({container: '#main',fragment: '#main'}).reload;
                    }
                })
                

            }
        });
    });
</script>